package com.ruoyi.bizsys.service.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Arrays;
import java.util.Map;

import com.ruoyi.common.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
    import com.ruoyi.bizsys.mapper.SmsTaskMapper;
import com.ruoyi.bizsys.domain.SmsTask;
import com.ruoyi.bizsys.service.ISmsTaskService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;


/**
 * 短信任务Service业务层处理
 *
 * @author african-loan
 * @date 2021-10-28
 */
@Service
public class SmsTaskServiceImpl extends ServiceImpl<SmsTaskMapper,SmsTask> implements ISmsTaskService {

    @Autowired
    SmsTaskMapper smsTaskMapper;
    /**
     * 查询短信任务
     *
     * @param id 短信任务ID
     * @return 短信任务
     */
    @Override
    public SmsTask selectSmsTaskById(Long id) {
        return this.getById(id);
    }

    /**
     * 查询短信任务列表
     *
     * @param smsTask 短信任务
     * @return 短信任务
     */
    @Override
    public List<SmsTask> selectSmsTaskList(SmsTask smsTask) {
        return this.list(new QueryWrapper<>(smsTask).last("order by id desc"));
    }

    /**
     * 新增短信任务
     *
     * @param smsTask 短信任务
     * @return 结果
     */
            @Override
    public int insertSmsTask(SmsTask smsTask) {
                                                                                                                                                                                                                                                                                                                                                                                                                                smsTask.setCreateTime(DateUtils.getNowDate());
                                                                    return baseMapper.insert(smsTask);
    }

    /**
     * 修改短信任务
     *
     * @param smsTask 短信任务
     * @return 结果
     */
            @Override
    public int updateSmsTask(SmsTask smsTask) {
                                                                                                                                                                                                                                                                                                                                                                                                                                                                        smsTask.setUpdateTime(DateUtils.getNowDate());
                            return baseMapper.updateById(smsTask);
    }

    /**
     * 批量删除短信任务
     *
     * @param ids 需要删除的短信任务ID
     * @return 结果
     */
            @Override
    public int deleteSmsTaskByIds(Long[] ids) {
        return baseMapper.deleteBatchIds(Arrays.asList(ids));
    }

    /**
     * 删除短信任务信息
     *
     * @param id 短信任务ID
     * @return 结果
     */
    @Override
    public int deleteSmsTaskById(Long id) {
        return baseMapper.deleteById(id);
    }

    @Override
    public int batchAdd(List<SmsTask> smsTaskList) {
        return smsTaskMapper.batchAdd(smsTaskList);
    }

    @Override
    public void updateBatchSmsTask(List<SmsTask> smsTaskList, int isSend) {
        Map<String,Object> map = new HashMap<>();
        map.put("list",smsTaskList);
        map.put("isSend",isSend);
        smsTaskMapper.updateBatchSmsTask(map);
    }

    @Override
    public int insertSql(String sqlStr) {
        return smsTaskMapper.insertSql(sqlStr);
    }

    @Override
    public List<SmsTask> selectSmsTask() {
        return smsTaskMapper.selectSmsTask();
    }

}
